package com.tianji.learning.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.learning.domain.dto.QuestionFormDTO;
import com.tianji.learning.domain.query.QuestionPageQuery;
import com.tianji.learning.domain.vo.QuestionVO;
import com.tianji.learning.service.IInteractionQuestionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 互动提问的问题表 前端控制器
 * </p>
 *
 * @author 陈彦祖
 * @since 2024-11-12
 */
@Api(tags = "互动提问-问题相关接口")
@RestController
@RequestMapping("/questions")
@RequiredArgsConstructor
public class InteractionQuestionController {

    private final IInteractionQuestionService questionService;

    /**1
     * 新增互动提问
     * @param questionFormDTO
     */
    @PostMapping
    @ApiOperation("新增互动提问")
    public void saveQuestion(@RequestBody @Valid QuestionFormDTO questionFormDTO){
        questionService.saveQuestion(questionFormDTO);
    }

    /**2
     * 分页查询互动问题列表
     * @param query
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("分页查询互动问题列表")
    public PageDTO<QuestionVO> pageQuestion(QuestionPageQuery query){
        return questionService.queryQuestionByPage(query);
    }
    /**3
     * 根据问题ID查询互动问题详情
     * @param
     */
    @ApiOperation("根据ID查询问题详情")
    @GetMapping("{id}")
    public QuestionVO queryById(@PathVariable("id") Long id){
        return questionService.queryById(id);
    }

    /**4
     * 删除互动问题
     * @param id
     */
    @DeleteMapping("/{id}")
    @ApiOperation("删除互动问题")
    public void deleteQuestion(@PathVariable("id") Long id){
        questionService.deleteQuestion(id);
    }

    /**5
     * 修改互动问题
     * @param id
     * @param questionFormDTO
     */
    @PutMapping("/{id}")
    @ApiOperation("修改互动问题")
    public void updateQuestion(@PathVariable("id") Long id, @RequestBody @Valid QuestionFormDTO questionFormDTO){
        questionService.updateQuestion(id,questionFormDTO);
    }
}
